package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.StrategyCatalog;
import cn.wolfcode.trip.base.query.StrategyCatalogQueryObject;
import cn.wolfcode.trip.base.service.IStrategyCatalogService;
import cn.wolfcode.trip.base.service.IStrategyService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 攻略目录资源控制器
 *
 * @author totoro93
 * @date 2019-01-11
 **/
@RequestMapping("/strategyCatalog")
@Controller
public class StrategyCatalogController {
    @Autowired
    private IStrategyCatalogService strategyCatalogService;

    @Autowired
    private IStrategyService strategyService;


    /**
     * 大攻略管理列表
     *
     * @param queryObject
     * @param model
     * @return
     */
    @RequestMapping("/list")
    public String list(@ModelAttribute("qo") StrategyCatalogQueryObject queryObject, Model model) {
        model.addAttribute("strategies", strategyService.listAll());
        model.addAttribute("pageInfo", strategyCatalogService.query(queryObject));
        return "strategyCatalog/list";
    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public JSONResult saveOrUpdate(StrategyCatalog strategyCatalog) {
        strategyCatalogService.saveOrUpdate(strategyCatalog);
        return new JSONResult();
    }
    @RequestMapping("/getCatalogByStrategyId")
    @ResponseBody
    public List getCatalogByStrategyId(Long strategyId) {
        return strategyCatalogService.selectByStrategyId(strategyId);
    }


}
